package gui;

import domein.Antwoord;
import domein.Vraag;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;

/**
 *
 * @author Robin
 */
public class QACellRenderer extends JLabel implements ListCellRenderer {

    public QACellRenderer() {
        setOpaque(true);
    }

    public Component getListCellRendererComponent(JList arg0, Object arg1, int arg2, boolean arg3, boolean arg4) {
        if (arg1.getClass().equals(Vraag.class)) {
            Vraag v = (Vraag) arg1;

            setHorizontalAlignment(SwingConstants.LEFT);
            setText("<html><table><td width='250'>" + v.getTekst() + "</td></table></html>");
            setBackground(Color.white);

        }
        if (arg1.getClass().equals(Antwoord.class)) {
            String s = "";
            s += ((Antwoord) arg1).getTekst();

            if (!s.equals("null")) {
                setText("<html><table><td width='250' align='right'>" + s + "</td></table></html>");
                setHorizontalAlignment(SwingConstants.RIGHT);
            } else {
                setText("");
            }
            setBackground(Color.gray);
        }
        return this;
    }
}
